 
var serverName = "http://127.0.0.1:50057"; // rob VS

$(document).ready(function() {

$("#f001").autocomplete({ 
		source: function( request, response ) {
			$.ajax({
				url: serverName+"/ACBServiceProxy.svc/Autolookup", type: 'POST', dataType: 'json', contentType: 'application/json; charset="utf-8"',				
				data: '{"search":"' + request.term + '","type":"Title"}',
				success: function (data) { response($.map(data.AutolookupResult, function (item) { return { label: item.Key + (item.Key==item.Val?"":" | " + item.Val),value: item.Key }})); }
			});
		}, minLength: 1
		// no select function
		});

$("#f002").autocomplete({
		source: function( request, response ) {
			$.ajax({
				url: serverName+"/ACBServiceProxy.svc/Autolookup", type: 'POST', dataType: 'json', contentType: 'application/json; charset="utf-8"',				
				data: '{"search":"' + request.term + '","type":"City"}',
				success: function (data) { response($.map(data.AutolookupResult, function (item) { return { label: item.Key + (item.Key==item.Val?"":" | " + item.Val),value: item.Key }})); }
			});
		}, minLength: 1 
		// no select function
		});				
		
$("#f003").autocomplete({ // display PostalCode in a different field
		source: function( request, response ) {
			$.ajax({
				url: serverName+"/ACBServiceProxy.svc/Autolookup", type: 'POST', dataType: 'json', contentType: 'application/json; charset="utf-8"',				
				data: '{"search":"' + request.term + '","type":"Suburb","parent":"' + document.getElementById('f002').value + '"}',
				success: function (data) { response($.map(data.AutolookupResult, function (item) { return { label: item.Key + (item.Key==item.Val?"":" | " + item.Val),value: item.Key }})); }
			});
		}, minLength: 1
		, select: function( event, ui ) { pieces = ui.item.label.split(" | "); document.getElementById('f004').value = pieces[1].trim(); }		
		});
		
$("#f004").autocomplete({ 
		source: function( request, response ) {
			$.ajax({
				url: serverName+"/ACBServiceProxy.svc/Autolookup", type: 'POST', dataType: 'json', contentType: 'application/json; charset="utf-8"',				
				data: '{"search":"' + request.term + '","type":"Code","parent":"' + document.getElementById('f002').value + '"}',
				success: function (data) { response($.map(data.AutolookupResult, function (item) { return { label: item.Key + (item.Key==item.Val?"":" | " + item.Val),value: item.Key }})); }
			});
		}, minLength: 1
		, select: function( event, ui ) { pieces = ui.item.label.split(" | "); document.getElementById('f003').value = pieces[1].trim(); }		
		});		

$("#f005").autocomplete({
		source: function( request, response ) {
			$.ajax({
				url: serverName+"/ACBServiceProxy.svc/Autolookup", type: 'POST', dataType: 'json', contentType: 'application/json; charset="utf-8"',				
				data: '{"search":"' + request.term + '","type":"Bank"}',
				success: function (data) { response($.map(data.AutolookupResult, function (item) { return { label: item.Key + (item.Key==item.Val?"":" | " + item.Val),value: item.Key }})); }
			});
		}, minLength: 1 
		// no select function
		});


$("#f006").autocomplete({ // display BankCode in a different field
		source: function( request, response ) {
			$.ajax({
				url: serverName+"/ACBServiceProxy.svc/Autolookup", type: 'POST', dataType: 'json', contentType: 'application/json; charset="utf-8"',				
				data: '{"search":"' + request.term + '","type":"BranchName","parent":"' + document.getElementById('f005').value + '"}',
				success: function (data) { response($.map(data.AutolookupResult, function (item) { return { label: item.Key + (item.Key==item.Val?"":" | " + item.Val),value: item.Key }})); }
			});
		}, minLength: 1
		, select: function( event, ui ) { pieces = ui.item.label.split(" | "); document.getElementById('f007').value = pieces[1].trim(); }		
		});

$("#f007").autocomplete({ // display BankCode in a different field
		source: function( request, response ) {
			$.ajax({
				url: serverName+"/ACBServiceProxy.svc/Autolookup", type: 'POST', dataType: 'json', contentType: 'application/json; charset="utf-8"',				
				data: '{"search":"' + request.term + '","type":"BranchCode","parent":"' + document.getElementById('f005').value + '"}',
				success: function (data) { response($.map(data.AutolookupResult, function (item) { return { label: item.Key + (item.Key==item.Val?"":" | " + item.Val),value: item.Key }})); }
			});
		}, minLength: 1
		, select: function( event, ui ) { pieces = ui.item.label.split(" | "); document.getElementById('f006').value = pieces[1].trim(); }				
		});
		
});